/*
 * Copyright (c) 2016 zhangcm. All Rights Reserved.
 */
package com.jnzc.ocr.serv.shop.api.impl;

import com.jnzc.ocr.common.bean.PageResult;
import com.jnzc.ocr.common.utils.ValidateUtils;
import com.jnzc.ocr.serv.shop.api.ShopMemberCategoryApi;
import com.jnzc.ocr.serv.shop.entity.ShopMemberCategory;
import com.jnzc.ocr.serv.shop.filter.ShopMemberCategoryFilter;
import com.jnzc.ocr.serv.shop.service.ShopMemberCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhangcm
 * @version 1.0, 2017/9/13
 */
@RestController
public class ShopMemberCategoryApiImpl implements ShopMemberCategoryApi {

    @Autowired
    private ShopMemberCategoryService shopMemberCategoryService;

    @Override
    public ShopMemberCategory find(@RequestParam("id") Long id, @RequestParam("shopId") Long shopId) {
        return shopMemberCategoryService.find(id, shopId);
    }

    @Override
    public List<ShopMemberCategory> list(@RequestBody ShopMemberCategoryFilter filter) {
        return shopMemberCategoryService.list(filter);
    }

    @Override
    public PageResult<ShopMemberCategory> search(@RequestBody ShopMemberCategoryFilter filter, @RequestParam Integer pageNo, @RequestParam Integer pageSize) {
        return shopMemberCategoryService.search(filter, pageNo, pageSize);
    }

    @Override
    public ShopMemberCategory save(@RequestBody ShopMemberCategory param) {
        ValidateUtils.isId(param.getShopId(), "店铺ID");
        ValidateUtils.notEmpty(param.getName(), 20, "店铺名称");
        ShopMemberCategory obj;
        if(null == param.getId()){
            obj = new ShopMemberCategory();
            obj.setShopId(param.getShopId());
        }else{
            obj = find(param.getId(), param.getShopId());
        }
        obj.setName(param.getName());
        return shopMemberCategoryService.save(obj);
    }

    @Override
    public void delete(@RequestParam("id") Long id, @RequestParam("shopId") Long shopId) {
        ShopMemberCategory obj = find(id, shopId);
        shopMemberCategoryService.delete(id);
    }
}
